$(document).ready(function(){
	freshMessageList();
});

function showMessageDetail(msgId) {
	requestUrl = "customer_json_servlet";
	var params = {
		request_method:"get_message_detail",
		type:$("#slt_mail_box").val(),
		message_id:msgId
	};
	
	$.post(requestUrl, params, function(data){
		var message = data.resultData;
		
		$("#div_message_detail").html("");
		$("#div_message_detail").css("display", "");
		var innerHtml = "";

		innerHtml += '	<div style="width: 390px; height: 50px; font-size: 15pt; font-weight: bold; border-bottom: 1px solid #c8c8c8;">';
		innerHtml += '		<span style="padding-top: 14px;">我的消息</span>';
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">标题:</span>';
		innerHtml += '		<span style="width: 250px; display: inline-block; font-weight: bold;">' + message.title + '</span>';
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">来自:</span>';
		innerHtml += '		<span style="color:#056a05;">' + message.senderName + '</span>';
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">时间:</span>';
		innerHtml += '		<span style="width: 250px; display: inline-block;">' + message.date + '</span>';
		innerHtml += '	</div>';
		
		$("#div_message_detail").html(innerHtml);

		addFadeEffect();
	}, "json");
}

/*
 * 刷新消息列表
 */
function freshMessageList() {
	requestUrl = "customer_json_servlet";
	var params = {
		request_method:"get_my_messages",
		type:$("#slt_mail_box").val(),
		page:1,
		page_size:999
	};

	$.post(requestUrl, params, function(data){
		var messages = data.resultData.items;
		var message;
		
		$("#div_message_detail").css("display", "none");
		$("#div_message_list").html("");
		var innerHtml = "";

		for (var i = 0; messages && i < messages.length; i++) {
			message = messages[i];
			
			innerHtml += '<div style="height: 50px; margin-left: 10px; border-bottom: 1px solid #e1e1e1; cursor: pointer;"';
			innerHtml += '	onclick="showMessageDetail(\'' + message.messageId + '\');">';
			innerHtml += '	<div>';
			if ($("#slt_mail_box").val() == "1") {
				innerHtml += '		<span style="width: 160px; display: inline-block;">' + message.senderId + '</span>';
			} else {
				innerHtml += '		<span style="width: 160px; display: inline-block;">' + message.receiverId + '</span>';
			}
			innerHtml += '		<span style="width: 160px; display: inline-block;">' + message.date + '</span>';
			innerHtml += '	</div>';
			innerHtml += '	<div>';
			innerHtml += '		<span style="width: 160px; display: inline-block;">' + message.title + '</span>';
			innerHtml += '	</div>';
			innerHtml += '</div>';
		}
		$("#div_message_list").html(innerHtml);
	}, "json");
}